<?php

/**
 * @Description    
 * @Author         zhaojiping
 * @Copyright      山东艾思软件科技有限公司(https://www.aisisofit.cn)
 * @Date           2022-6-15
 * @CreateBy       vs code
 */


namespace app\base\controller;

use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;


class OssController {
    public function sts() {

        $config = cache('config');
        $bucket = $config["cos_bucket"];   // 存储桶
        $region = $config["cos_region"]; // 地区
        $secretId = $config["cos_secret_id"];  // 密钥ID
        $secretKey = $config["cos_secret_key"]; // 密钥

        // lneas.oss-cn-beijing.aliyuncs.com

        //构建一个阿里云客户端，用于发起请求。
        //构建阿里云客户端时需要设置AccessKey ID和AccessKey Secret。
        AlibabaCloud::accessKeyClient('LTAI5tGe45X7nkPEZw5UStMG', 'tKaT847EBbYNBD7dtnOwpuwfRvnxzW')
            ->regionId('cn-hangzhou')
            ->asDefaultClient();
        //设置参数，发起请求。关于参数含义和设置方法，请参见《API参考》。
        try {
            $result = AlibabaCloud::rpc()
                ->product('Sts')
                ->scheme('https') // https | http
                ->version('2015-04-01')
                ->action('AssumeRole')
                ->method('POST')
                ->host('sts.aliyuncs.com')
                ->options([
                    'query' => [
                        'RoleArn' => "acs:ram::1387482186800585:role/stsrole",
                        'RoleSessionName' => "ems",
                    ],
                ])
                ->request();
            json_return(1, '', $result->toArray());
        } catch (ClientException $e) {
            echo $e->getErrorMessage() . PHP_EOL;
        } catch (ServerException $e) {
            echo $e->getErrorMessage() . PHP_EOL;
        }
    }
}
